﻿class com.nesium.utils.Delay
	// v1.03
{

	private	var __obj			: Object;
	private	var __func			: Function;
	private	var __args			: Array;
	private	var __delay		: Number;
	private	var __intvl		: Number;
	
	
	public function Delay( obj, func, args, delay )
	{
		if ( arguments.length == 3 )
		{
			__obj		= null;
			__func 	= obj;
			__args 	= func;
			__delay	= args;
		}
		else if ( arguments.length == 4 )
		{
			__obj 	= obj;
			__func 	= obj[ func ];
			__args	= args;
			__delay	= delay;
		}
	}
	
	public function start( Void ) : Void
	{
		__intvl = setInterval( this, "stopDelay", __delay );
	}
	
	private function stopDelay( Void ) : Void
	{
		clearInterval( __intvl );
		callback();
	}
	
	private function callback( Void ) : Void
	{
		__func.apply( __obj, __args );
	}
	
	public function kill( Void ) : Void
	{
		clearInterval( __intvl );
	}
	
	public function setDelay( d : Number ) : Void
	{
		__delay = d;
	}
}